package com.cjj.common.enums;

/**
 * 帖子类型枚举
 */
public enum PostType {
    QUESTION("QUESTION", "提问"),
    SHARE("SHARE", "分享");
    
    private final String value;
    private final String desc;
    
    PostType(String value, String desc) {
        this.value = value;
        this.desc = desc;
    }
    
    public String getValue() {
        return value;
    }
    
    public String getDesc() {
        return desc;
    }
    
    /**
     * 通过值查找枚举
     */
    public static PostType fromValue(String value) {
        for (PostType type : values()) {
            if (type.getValue().equals(value)) {
                return type;
            }
        }
        throw new IllegalArgumentException("未知的帖子类型: " + value);
    }
    
    /**
     * 检查值是否有效
     */
    public static boolean isValid(String value) {
        for (PostType type : values()) {
            if (type.getValue().equals(value)) {
                return true;
            }
        }
        return false;
    }
    
    /**
     * 获取所有可选值
     */
    public static String[] getAllValues() {
        PostType[] types = values();
        String[] values = new String[types.length];
        for (int i = 0; i < types.length; i++) {
            values[i] = types[i].getValue();
        }
        return values;
    }
    
    /**
     * 获取所有描述
     */
    public static String[] getAllDescs() {
        PostType[] types = values();
        String[] descs = new String[types.length];
        for (int i = 0; i < types.length; i++) {
            descs[i] = types[i].getDesc();
        }
        return descs;
    }
    
    @Override
    public String toString() {
        return value;
    }
}